package map;

import map.domain.Person;

import java.util.HashMap;
import java.util.TreeMap;

/*
双列集合底层的数据结构，都是针对于键有效，跟值没有关系
    HashMap ：键唯一(需要重写hashCode方法和equals方法)   哈希表
    TreeMap ：键排序(需要实现Comparable接口)            红黑树
    LinkedHashMap ：键唯一且可以保证存取的顺序           哈希表+双向链表
 */
public class MapDemo02 {
    public static void main(String[] args) {
        showHashMap();
        showTreeMap();
        showLinkedHashMap();
    }
    private static void showHashMap(){
        HashMap<Person,String> hm = new HashMap<>();
        hm.put(new Person("张三",23),"上海");
        hm.put(new Person("作者",23),"武汉");
        hm.put(new Person("帆帆",23),"成都");
        hm.put(new Person("张三",23),"北京");
        System.out.println(hm);

    }
    private static void showTreeMap(){
        TreeMap<Person,String> tm = new TreeMap<>();
        tm.put(new Person("张三",23),"上海");
        tm.put(new Person("作者",26),"武汉");
        tm.put(new Person("帆帆",28),"成都");
        tm.put(new Person("张三",23),"北京");
        System.out.println(tm);
    }
    private static void showLinkedHashMap(){
        TreeMap<Person,String> lhm = new TreeMap<>();
        lhm.put(new Person("张三",23),"上海");
        lhm.put(new Person("作者",26),"武汉");
        lhm.put(new Person("帆帆",28),"成都");
        lhm.put(new Person("张三",23),"北京");
        System.out.println(lhm);
    }
}
